using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Daniel.Core.Models.Mapping
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(400);

            this.Property(t => t.MetaKeywords)
                .HasMaxLength(400);

            this.Property(t => t.MetaTitle)
                .HasMaxLength(400);

            this.Property(t => t.Sku)
                .HasMaxLength(400);

            this.Property(t => t.ManufacturerPartNumber)
                .HasMaxLength(400);

            this.Property(t => t.Gtin)
                .HasMaxLength(400);

            this.Property(t => t.RequiredProductIds)
                .HasMaxLength(1000);

            this.Property(t => t.AllowedQuantities)
                .HasMaxLength(1000);

            // Table & Column Mappings
            this.ToTable("Product");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ProductTypeId).HasColumnName("ProductTypeId");
            this.Property(t => t.ParentGroupedProductId).HasColumnName("ParentGroupedProductId");
            this.Property(t => t.VisibleIndividually).HasColumnName("VisibleIndividually");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.ShortDescription).HasColumnName("ShortDescription");
            this.Property(t => t.FullDescription).HasColumnName("FullDescription");
            this.Property(t => t.AdminComment).HasColumnName("AdminComment");
            this.Property(t => t.ProductTemplateId).HasColumnName("ProductTemplateId");
            this.Property(t => t.VendorId).HasColumnName("VendorId");
            this.Property(t => t.ShowOnHomePage).HasColumnName("ShowOnHomePage");
            this.Property(t => t.MetaKeywords).HasColumnName("MetaKeywords");
            this.Property(t => t.MetaDescription).HasColumnName("MetaDescription");
            this.Property(t => t.MetaTitle).HasColumnName("MetaTitle");
            this.Property(t => t.AllowCustomerReviews).HasColumnName("AllowCustomerReviews");
            this.Property(t => t.ApprovedRatingSum).HasColumnName("ApprovedRatingSum");
            this.Property(t => t.NotApprovedRatingSum).HasColumnName("NotApprovedRatingSum");
            this.Property(t => t.ApprovedTotalReviews).HasColumnName("ApprovedTotalReviews");
            this.Property(t => t.NotApprovedTotalReviews).HasColumnName("NotApprovedTotalReviews");
            this.Property(t => t.SubjectToAcl).HasColumnName("SubjectToAcl");
            this.Property(t => t.LimitedToStores).HasColumnName("LimitedToStores");
            this.Property(t => t.Sku).HasColumnName("Sku");
            this.Property(t => t.ManufacturerPartNumber).HasColumnName("ManufacturerPartNumber");
            this.Property(t => t.Gtin).HasColumnName("Gtin");
            this.Property(t => t.IsGiftCard).HasColumnName("IsGiftCard");
            this.Property(t => t.GiftCardTypeId).HasColumnName("GiftCardTypeId");
            this.Property(t => t.RequireOtherProducts).HasColumnName("RequireOtherProducts");
            this.Property(t => t.RequiredProductIds).HasColumnName("RequiredProductIds");
            this.Property(t => t.AutomaticallyAddRequiredProducts).HasColumnName("AutomaticallyAddRequiredProducts");
            this.Property(t => t.IsDownload).HasColumnName("IsDownload");
            this.Property(t => t.DownloadId).HasColumnName("DownloadId");
            this.Property(t => t.UnlimitedDownloads).HasColumnName("UnlimitedDownloads");
            this.Property(t => t.MaxNumberOfDownloads).HasColumnName("MaxNumberOfDownloads");
            this.Property(t => t.DownloadExpirationDays).HasColumnName("DownloadExpirationDays");
            this.Property(t => t.DownloadActivationTypeId).HasColumnName("DownloadActivationTypeId");
            this.Property(t => t.HasSampleDownload).HasColumnName("HasSampleDownload");
            this.Property(t => t.SampleDownloadId).HasColumnName("SampleDownloadId");
            this.Property(t => t.HasUserAgreement).HasColumnName("HasUserAgreement");
            this.Property(t => t.UserAgreementText).HasColumnName("UserAgreementText");
            this.Property(t => t.IsRecurring).HasColumnName("IsRecurring");
            this.Property(t => t.RecurringCycleLength).HasColumnName("RecurringCycleLength");
            this.Property(t => t.RecurringCyclePeriodId).HasColumnName("RecurringCyclePeriodId");
            this.Property(t => t.RecurringTotalCycles).HasColumnName("RecurringTotalCycles");
            this.Property(t => t.IsShipEnabled).HasColumnName("IsShipEnabled");
            this.Property(t => t.IsFreeShipping).HasColumnName("IsFreeShipping");
            this.Property(t => t.AdditionalShippingCharge).HasColumnName("AdditionalShippingCharge");
            this.Property(t => t.DeliveryDateId).HasColumnName("DeliveryDateId");
            this.Property(t => t.WarehouseId).HasColumnName("WarehouseId");
            this.Property(t => t.IsTaxExempt).HasColumnName("IsTaxExempt");
            this.Property(t => t.TaxCategoryId).HasColumnName("TaxCategoryId");
            this.Property(t => t.ManageInventoryMethodId).HasColumnName("ManageInventoryMethodId");
            this.Property(t => t.StockQuantity).HasColumnName("StockQuantity");
            this.Property(t => t.DisplayStockAvailability).HasColumnName("DisplayStockAvailability");
            this.Property(t => t.DisplayStockQuantity).HasColumnName("DisplayStockQuantity");
            this.Property(t => t.MinStockQuantity).HasColumnName("MinStockQuantity");
            this.Property(t => t.LowStockActivityId).HasColumnName("LowStockActivityId");
            this.Property(t => t.NotifyAdminForQuantityBelow).HasColumnName("NotifyAdminForQuantityBelow");
            this.Property(t => t.BackorderModeId).HasColumnName("BackorderModeId");
            this.Property(t => t.AllowBackInStockSubscriptions).HasColumnName("AllowBackInStockSubscriptions");
            this.Property(t => t.OrderMinimumQuantity).HasColumnName("OrderMinimumQuantity");
            this.Property(t => t.OrderMaximumQuantity).HasColumnName("OrderMaximumQuantity");
            this.Property(t => t.AllowedQuantities).HasColumnName("AllowedQuantities");
            this.Property(t => t.AllowAddingOnlyExistingAttributeCombinations).HasColumnName("AllowAddingOnlyExistingAttributeCombinations");
            this.Property(t => t.DisableBuyButton).HasColumnName("DisableBuyButton");
            this.Property(t => t.DisableWishlistButton).HasColumnName("DisableWishlistButton");
            this.Property(t => t.AvailableForPreOrder).HasColumnName("AvailableForPreOrder");
            this.Property(t => t.PreOrderAvailabilityStartDateTimeUtc).HasColumnName("PreOrderAvailabilityStartDateTimeUtc");
            this.Property(t => t.CallForPrice).HasColumnName("CallForPrice");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.OldPrice).HasColumnName("OldPrice");
            this.Property(t => t.ProductCost).HasColumnName("ProductCost");
            this.Property(t => t.SpecialPrice).HasColumnName("SpecialPrice");
            this.Property(t => t.SpecialPriceStartDateTimeUtc).HasColumnName("SpecialPriceStartDateTimeUtc");
            this.Property(t => t.SpecialPriceEndDateTimeUtc).HasColumnName("SpecialPriceEndDateTimeUtc");
            this.Property(t => t.CustomerEntersPrice).HasColumnName("CustomerEntersPrice");
            this.Property(t => t.MinimumCustomerEnteredPrice).HasColumnName("MinimumCustomerEnteredPrice");
            this.Property(t => t.MaximumCustomerEnteredPrice).HasColumnName("MaximumCustomerEnteredPrice");
            this.Property(t => t.HasTierPrices).HasColumnName("HasTierPrices");
            this.Property(t => t.HasDiscountsApplied).HasColumnName("HasDiscountsApplied");
            this.Property(t => t.Weight).HasColumnName("Weight");
            this.Property(t => t.Length).HasColumnName("Length");
            this.Property(t => t.Width).HasColumnName("Width");
            this.Property(t => t.Height).HasColumnName("Height");
            this.Property(t => t.AvailableStartDateTimeUtc).HasColumnName("AvailableStartDateTimeUtc");
            this.Property(t => t.AvailableEndDateTimeUtc).HasColumnName("AvailableEndDateTimeUtc");
            this.Property(t => t.DisplayOrder).HasColumnName("DisplayOrder");
            this.Property(t => t.Published).HasColumnName("Published");
            this.Property(t => t.Deleted).HasColumnName("Deleted");
            this.Property(t => t.CreatedOnUtc).HasColumnName("CreatedOnUtc");
            this.Property(t => t.UpdatedOnUtc).HasColumnName("UpdatedOnUtc");

            // Relationships
            this.HasMany(t => t.ProductTags)
                .WithMany(t => t.Products)
                .Map(m =>
                    {
                        m.ToTable("Product_ProductTag_Mapping");
                        m.MapLeftKey("Product_Id");
                        m.MapRightKey("ProductTag_Id");
                    });


        }
    }
}
